<template>
	<view>
		<view class="sticky-box">
			<view :style="{ height: statusBarHeight }" class="uni-status-bar"></view>
			<view class="nav-bar">
				<view class="more-view" @tap="showDrawer">
					<image class="more-icon" src="../../static/img/more.png" mode="scaleToFill"></image>
				</view>
				<view class="flex-col nav-title" @tap="toLogin()">
					<view class="flex-row hospital-name">
						<text>{{userInfo.departmentName}}</text>
						<text v-if="userInfo.realName && userInfo.realName !== ''">({{userInfo.realName}})</text>
					</view>
					<text class="app-name">{{AppName}}({{AppVersion}})</text>
				</view>
			</view>
		</view>
		<view class="sheet-list">
			<view class="flex-col sheet-item"
				@tap="toPageUrl(item)"
				v-for="(item, index) in sheetList" :key="index">
				<image class="sheet-img" :src="item.img" mode="scaleToFill"></image>
				<text class="sheet-text" >{{item.title}}</text>
			</view>
		</view>
		<!-- 侧边弹窗 -->
		<uni-drawer ref="showLeft" mode="left">
			<view class="flex-col">
				<view :style="{ height: statusBarHeight }" class="uni-status-bar"></view>
				<view class="flex-col drawer-more">
					<text class="drawer-more-text">更多</text>
				</view>
				<view class="flex-row drawer-row" @tap="toSetServer">
					<text class="drawer-row-left">设置服务器地址</text>
					<image class="arrow-icon" src="../../static/img/right_arrow.png" mode="scaleToFill"></image>
				</view>
				<view class="flex-row drawer-row" @tap="toLogin">
					<text class="drawer-row-left">登录</text>
					<image class="arrow-icon" src="../../static/img/right_arrow.png" mode="scaleToFill"></image>
				</view>
				<view class="flex-row drawer-row" @tap="toChangePassword">
					<text class="drawer-row-left">修改密码</text>
					<image class="arrow-icon" src="../../static/img/right_arrow.png" mode="scaleToFill"></image>
				</view>
				<view class="flex-row drawer-row" @tap="logoutApp">
					<text class="drawer-row-left">退出登录</text>
					<image class="arrow-icon" src="../../static/img/right_arrow.png" mode="scaleToFill"></image>
				</view>
				<view class="flex-row drawer-row" @tap="backApp">
					<text class="drawer-row-left">退出APP</text>
					<image class="arrow-icon" src="../../static/img/right_arrow.png" mode="scaleToFill"></image>
				</view>
			</view>
		</uni-drawer>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex'
	var statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px'
	var that;
	export default {
		data() {
			return {
				statusBarHeight: statusBarHeight,
				hospitalName: '',
				AppName: '处方外配系统',
				AppVersion: '1.0.2',
				sheetList: [
					// {
					// 	img: '../../static/img/pick_kind2.png',
					// 	title: '药库入库',
					// 	text: '点击开始入库',
					// 	url:'/pagesStockIn/goodsList/goodsList',
					// 	//url: '/pagesStockIn/deliveryCompanyList/deliveryCompanyList',
					// 	type: 'stock', 
					// 	kind: 'Pharmacy1StockOut',
					// 	AppCode: 'App101'
					// },
					{
						img: '../../static/img/pick_kind2.png',
						title: '外配处方',
						text: '点击开始入库',
						url:'/pagesStockIn/goodsList/goodsList',
						//url: '/pagesStockIn/deliveryCompanyList/deliveryCompanyList',
						type: 'stock', 
						kind: 'Pharmacy1StockOut',
						AppCode: 'App101'
					},
					// {
					// 	img: '../../static/img/pick_kind2.png',
					// 	title: '商品对码',
					// 	text: '点击扫描电子监管码',
					// 	url: '/pagesContrast/goodsContrast/goodsContrast',
					// 	type: 'pick', 
					// 	kind: 'Pharmacy1StockOut',
					// 	AppCode: 'App105'
					// },
					// {
					// 	img: '../../static/img/pick_kind2.png',
					// 	title: '扫码拆零',
					// 	text: '点击扫描电子监管码',
					// 	url: '/pages/cailing/cailing',
					// 	type: 'pick', 
					// 	kind: 'Pharmacy1StockOut',
					// 	AppCode: 'App106'
					// },
					// {
					// 	img: '../../static/img/pick_kind2.png',
					// 	title: '扫码拒收',
					// 	text: '点击扫描电子监管码',
					// 	url: '',
					// 	type: 'pick', 
					// 	kind: 'Pharmacy1StockOut',
					// 	AppCode: 'App106'
					// },
					// {
					// 	img: '../../static/img/pick_kind2.png',
					// 	title: '扫码退厂',
					// 	text: '点击扫描电子监管码',
					// 	url: '/pagesStockOut/goodsList/goodsList',
					// 	//url: '/pagesStockOut/deliveryCompanyList/deliveryCompanyList',
					// 	type: 'pick', 
					// 	kind: 'Pharmacy1StockOut',
					// 	AppCode: 'App106'
					// },
					// {
					// 	img: '../../static/img/pick_kind2.png',
					// 	title: '药房发药',
					// 	text: '点击扫描电子监管码',
					// 	url: '',
					// 	type: 'pick', 
					// 	kind: 'Pharmacy1StockOut',
					// 	AppCode: 'App106'
					// },
					// {
					// 	img: '../../static/img/pick_kind2.png',
					// 	title: '统计',
					// 	text: '点击扫描电子监管码',
					// 	url: '',
					// 	type: 'pick', 
					// 	kind: 'Pharmacy1StockOut',
					// 	AppCode: 'App106'
					// },
				]
			}
		},
		computed: {
			...mapState({
				userInfo: state => state.userInfo, // userInfo
				Token: state => state.Token, // Token
			})  
		},
		onLoad() {
			that = this;
			uni.getSystemInfo({
				success: (res) => {
					var _this = this;
					// 检测当前平台，如果是安卓则启动安卓更新  
					if (res.platform == "android") {
						//  获取manifest.json里的配置信息
						plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
							that.AppName = wgtinfo.name;
							that.AppVersion = wgtinfo.versionCode;					
						});
					}
				}
			})
			
			
			
			
		},
		onShow() {
			that.initUserInfo()
		},
		methods: {
			...mapMutations(['logout']),
			initUserInfo() {
				if(that.Token != '') {
					that.isLogin = true;
					that.hospitalName = that.userInfo.UserDeptName
				} else {
					that.isLogin = false;
					that.hospitalName = '未登录'
				}
			},
			getServerData() {
				
			},
			showDrawer() {
				that.openPopup('showLeft')
			},
			openPopup(ref) {
				this.$refs[ref].open();
			},
			closePopup(ref) {
				this.$refs[ref].close();
			},
			toLogin() {
				uni.navigateTo({
					url: '../login/login'
				})
			},
			logoutApp() {
				that.$request.globalRequest('user/logout', 'POST', {}, '', 0).then(res => {
					that.logout();
					that.hospitalName = '未登录';
					that.isLogin = false;
					that.closePopup('showLeft')
					const url = {
						path: '/pages/index/index', 
						query: { 
							title: '', 
							type: '',
						}
					}
					that.$Router.replaceAll(url)
				}).catch( res => {					
					that.$common.showNormalToast(res);					
				})	
				
			},
			toSetServer() {
				let url = {
					path: '/pages/server/server', 
					query: { 
						title: '', 
						type: '',
					}
				}
				that.$Router.push(url)
			},
			toChangePassword() {
				let url = {
					path: '/pages/changePassword/changePassword', 
					query: { 
						title: '', 
						type: '',
					}
				}
				that.$Router.push(url)
			},
			backApp() {
				that.closePopup('showLeft');
				uni.showModal({
					title: '提示',  
					content: '是否退出？', 
					cancelColor: '#1983e8;',
					confirmColor: '#1983e8;',
					success: function(res) {  
						if (res.confirm) {  
							// 退出当前应用，改方法只在App中生效  
							plus.runtime.quit();  
						} else if (res.cancel) {  
							 
						}  
					}  
				});  
			},
			toPageUrl(item) {
				if (!item.url) {
					return;
				}
				const url = {
					path: item.url, 
					query: { 
						title: '',
						type: ''
					}
				}
				that.$Router.push(url)
			},
			// logoutApp() {
			// 	that.logout();
			// 	const url = {
			// 		path: '/pages/index/index', 
			// 		query: { 
			// 			title: '', 
			// 			type: '',
			// 		}
			// 	}
			// 	that.$Router.replaceAll(url)
			// },
		}
	}
</script>

<style lang="scss" scoped>
@import "inde.scss"
</style>
